const express = require('express');
const router = express.Router();
const { check } = require('express-validator');
const groupController = require('../controllers/groupController');
const authMiddleware = require('../middleware/auth');

router.post(
    '/',
    authMiddleware,
    [
        check('name').notEmpty().withMessage('Group name is required'),
        check('user_ids').isArray().notEmpty().withMessage('User IDs are required')
    ],
    groupController.createGroup
);

router.post(
    '/:group_id/messages',
    authMiddleware,
    [check('content').notEmpty().withMessage('Content is required')],
    groupController.sendMessage
);

router.get('/:group_id/messages', authMiddleware, groupController.getMessages);

module.exports = router;